package com.kqkj.dyrule.datagen;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

//运行一次，生成一条行为日志,传输给kafka,通过engine为kafka存储到clickhouse
public class ActionLogGenOne {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers","kqkj101:9092,kqkj102:9092,kqkj103:9092");
        properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<>(properties);
        LogBean logBean = new LogBean();
        logBean.setDeviceId("000053");
        logBean.setEventId("E");
        Map<String,String> ps = new HashMap();
        logBean.setProperties(ps);
        logBean.setTimeStamp(System.currentTimeMillis());
        String log = JSON.toJSONString(logBean);
        ProducerRecord<String, String> record = new ProducerRecord<>("zenniu_applog", log);
        kafkaProducer.send(record);
        kafkaProducer.flush();


    }
}
